Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let the script processer pick custom transformers when present #154

Merged
merged 2 commits into from
Jan 31, 2019

Conversation

yohodopo
Copy link
Contributor

@yohodopo yohodopo commented Jan 30, 2019

This PR enables the use of custom script transformers, resolves extends property from tsconfig.json.

Similar to custom CSS transformers this help when we have any custom processing to the script(ts/js/coffee).

For eg. When users do not have babel.config.js at the root of the application but have it at a specific location, we can create a custom babel-transformer by passing in babel-jest's createTransformer(babelConfig) with the config pointing to the babel configuration.

Fixes, #148, #144

@@ -64,7 +64,8 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) {

const getTsJestConfig = function getTsJestConfig(config) {
const tr = createTransformer()
return tr.configsFor(config)
const { typescript } = tr.configsFor(config)
return { compilerOptions: typescript.options }
Copy link
Contributor Author

@yohodopo yohodopo Jan 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we could do something like the this to make sure we dont depend on ts-jest to fetch tsConfig options when users do not use ts-jest at all.

const getTsJestConfig = function getTsJestConfig(config = {}) {
  const vueTsConfig = getVueJestConfig(config)
  if (typeof vueTsConfig.tsConfig === 'string') {
    return getTsConfigJson(vueTsConfig.tsConfig)
  } else if (typeof vueTsConfig.tsConfig === 'object') {
    return vueTsConfig.tsConfig
  } else if (config.globals && config.globals['ts-jest']) {
    const tr = createTransformer()
    const {
      typescript: { options: compilerOptions }
    } = tr.configsFor(config)
    return { compilerOptions }
  } else {
    // auto pick tsconfig from the root folder
    return getTsConfigJson()
  }
}

const getTsConfigJson = function getTsConfigJson(
  pathToConfig = path.resolve(process.cwd(), './tsconfig.json')
) {
  const configJson = ts.parseConfigFileTextToJson(
    pathToConfig,
    ts.sys.readFile(pathToConfig)
  )
  const { options: compilerOptions } = ts.parseJsonConfigFileContent(
    configJson.config,
    ts.sys,
    ts.getDirectoryPath(pathToConfig),
    {},
    pathToConfig
  )
  return { compilerOptions }
}

Or should we use @babel/preset-typescript to transpile .ts files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyerburgh thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most use cases it would be fine to compile with Babel, it would also simplify the code. The only problem would be if users use const enums, namespaces, or export = or import =.

I haven't seen anyone using those features in components, so I think we can go ahead with using Babel for compiling TypeScript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we added ts-jest, Jest added native support for TypeScript in v24 (which uses Babel), so I think we are fine to remove ts-jest and just use Babel.

Copy link
Member

@eddyerburgh eddyerburgh Jan 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please make this change in a new PR

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Can you please make another PR to swap ts-jest for babel-jest?

@eddyerburgh eddyerburgh merged commit 8fc56d0 into vuejs:master Jan 31, 2019
@eddyerburgh
Copy link
Member

Are you planning to open a PR to remove TypeScript and use babel instead?

@yohodopo
Copy link
Contributor Author

yohodopo commented Feb 5, 2019

Hey @eddyerburgh , I've not had enough time to work on it. Will create a PR over the weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants